<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>部门</span>
          <input v-model="bumen" type="text" placeholder="请输入部门" />
        </p>
        <h3 @click="getList">查询</h3>
        <h4 @click="resetList">重置</h4>
				<h3 @click="addPeople" style="background: #0093FF">新增</h3>
      </div>
      <div class="zd3-btm">
        <!-- <div class="zd3-btm-title">
          <p style="width: 100px">状态</p>
          <p style="flex: 1">标题</p>
          <p style="flex: 1">部门名称</p>
					<p style="flex: 1">文档信息</p>
					<p style="flex: 1">提交人</p>
					<p style="flex: 1">备注</p>
          <p style="width: 250px;">操作</p>
        </div> -->
        <!-- <div class="addDate" @click="addPeople">+ 新增重点项目情况</div> -->
        <el-table
          :data="tableData"
          style="width: 100%;margin-bottom: 20px;"
          v-loading="loading"
        >
          <el-table-column align="center" width="100" label="状态" >
            <template slot-scope="scope">
              <div class="orderStatus">
								<p v-if='scope.row.status == 0' class="yellow">未确认</p>
								<p v-if='scope.row.status == 1' class="blue">进行中</p>
								<p v-if='scope.row.status == 2' class="green">落实</p>
								<p v-if='scope.row.status == 3' class="green">进度</p>
								<p v-if='scope.row.status == 4' class="blue">完成</p>
                <p v-if='scope.row.status == 111' class="zise">审核</p>
                <p v-if='scope.row.status == 222' class="zise">审核</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="titles" label="标题"></el-table-column>
          <el-table-column align="center" prop="deparement" label="部门名称"></el-table-column>
          <el-table-column align="center" prop="parentFile" label="文档信息">
            <template slot-scope="scope">
              <p @click="downloadFile(scope.row.parentFile)" class="downloadfile">下载<i class="el-icon-download" /></p>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="persons" label="提交人"></el-table-column>
          <el-table-column align="center" prop="remartks" label="备注"></el-table-column>
          <el-table-column align="center" width="250" label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="look(scope.row)">查看</el-button>
              <el-button type="text" size="small" @click="write(scope.row,scope.$index)" v-if="scope.row.status == 0 && userinfo.departments == '企管部'">修改</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
                v-if="scope.row.status == 0 && userinfo.departments == '企管部'"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
              <el-popover placement="bottom" width="160" v-if="scope.row.status != 4">
                <div class="morehandle">
                  <el-button type="text" size="small" v-if="scope.row.status == 0 && userinfo.username == scope.row.persons" @click="sureBegin(scope.row,scope.$index)">确认开始</el-button>
							    <el-button type="text" size="small" v-if="scope.row.status != 0" @click="jindu(scope.row)">进度情况</el-button>
                  <el-button type="text" size="small" v-if="userinfo.departments == '企管部' && scope.row.status != 0" @click="luoshi(scope.row)">落实情况</el-button>
                  <!-- <el-button type="text" size="small" v-if="userinfo.departments == '企管部' && scope.row.status != 0" @click="sureFinish(scope.row)">确认完成</el-button> -->
                  <el-button type="text" size="small" v-if="userinfo.departments == '企管部' && scope.row.status != 0 && userinfo.username == scope.row.persons && scope.row.status != 222" @click="tijiao(scope.row)">提交审核</el-button>
                  <el-button type="text" size="small" v-if="userinfo.departments == '企管部' && scope.row.status != 0 && userinfo.power != '员工' && userinfo.power == scope.row.contents" @click="shenhe(scope.row)">审核</el-button>
                </div>
                <el-button type="text" size="mini" slot="reference">
                  更多操作
                  <i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
              </el-popover>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          align="right"
          layout="prev, pager, next"
          :total="total"
          :page-size="50"
          @prev-click="goPrev"
          @next-click="goNext"
          @current-change="goPage"
        />
      </div>
    </div>
    <el-dialog title="确认审核" :close-on-click-modal="false" :visible.sync="spBox" width="70%">
		  <div class="change">
		    <p>
					<span>操作</span>
		      <el-radio v-model="spItem.result" label='true'>同意</el-radio>
		      <el-radio v-model="spItem.result" label='false'>驳回</el-radio>
		    </p>
				<p>
					<span>评价结果</span>
				  <el-input type="text" v-model="spItem.evalresult" placeholder="请输入评价结果" class="userselect"></el-input>
				</p>
		  </div>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="spBox = false">取 消</el-button>
		    <el-button type="primary" @click="buzhangSh" :disabled="isClick">确 定</el-button>
		  </span>
		</el-dialog>
  </div>
</template>

<script>
// import { getBumen,updateBumen,addBumen,deleteBumen } from '@/api/people'
// 重点项目信息模块，页面暂时看不到
import { getDetail,updateDetail,addDetail,deleteDetail,addShenHe,selectShenHe } from '@/api/keyprojects'
// let userinfo = null
let content = null
export default {
  data() {
    return {
      name: "",
      bumen: "",
      total: 1,
      pages: 1,
      showHeader: false,
			userinfo: '',
      tableData: [],
      dialogVisible: false,
      tempData: "",
      tempIndex: -1,
      loading: true,
      userType: '',   //登录人身份
			spItem: {},    //部长审批数据
			spBox: false,
			isClick: false,   //是否点击
    };
  },
  mounted(){
		this.userinfo = this.$store.state.user.userInfo[0]
    console.log('this.userinfo',this.userinfo)
    this.getList()
  },
  methods: {
    getList() {
      // let that = this
      const param = {
        deparement: this.userinfo.departments != '企管部' ? this.userinfo.departments : null,
        currentPage: this.pages
      }
      // console.log('param',param)
      getDetail(param).then(res => {
        console.log('部门管理')
        console.log(res)
        console.log(this.userinfo.departments)
        this.tableData = res.data.records
				this.total = res.data.total
				// this.tableData = filterlist
        this.loading = false
      })
    },
    // 提交审核
    tijiao(item){
      updateDetail({id:item.id,status: 222,contents: '部长'}).then(res => {
        console.log(res)
        this.$message({
          message: res.message,
          type:'success'
        })
        this.getList()
      })
    },
    // 确认完成
    sureFinish(item){
      updateDetail({id:item.id,status: 4}).then(res => {
        console.log(res)
        this.$message({
          message: res.message,
          type:'success'
        })
        this.getList()
      })
    },
    // 审核弹窗
    shenhe(item){
      console.log(item)
      this.spItem = {...item}
      this.spBox = true
    },
    // 确定审核
    buzhangSh(){
      console.log(this.spItem.result)
      // 如果处理结果为通过
      if(this.spItem.result == 'true'){
        // 等于部长的时候证明该部长操作
        if(this.spItem.contents == '部长'){
          addShenHe({
            prointId: this.spItem.id,
            evalresult: this.spItem.evalresult,
            result: this.spItem.result,
            content: '部长'
          }).then(res => {
            console.log(res)
            this.spBox = false
          })
          updateDetail({id:this.spItem.id,contents: '总监'}).then(res => {
            console.log(res)
            this.$message({
              message: res.message,
              type:'success'
            })
            this.getList()
          })
        }else{
          addShenHe({
            prointId: this.spItem.id,
            evalresult: this.spItem.evalresult,
            result: this.spItem.result,
            content: '总监'
          }).then(res => {
            console.log(res)
            this.spBox = false
            this.$message({
              message: res.message,
              type:'success'
            })
            updateDetail({id:this.spItem.id,status: 4}).then(res => {
              console.log(res)
              this.getList()
            })
          })
        }
      }else{
         // 处理结果为不通过
        if(this.spItem.contents == '部长'){
          addShenHe({
            prointId: this.spItem.id,
            evalresult: this.spItem.evalresult,
            result: this.spItem.result,
            content: '部长'
          }).then(res => {
            console.log(res)
            this.spBox = false
          })
          updateDetail({id:this.spItem.id,contents: '',status: 1}).then(res => {
            console.log(res)
            this.$message({
              message: res.message,
              type:'success'
            })
            this.getList()
          })
        }else{
          addShenHe({
            prointId: this.spItem.id,
            evalresult: this.spItem.evalresult,
            result: this.spItem.result,
            content: '总监'
          }).then(res => {
            console.log(res)
            this.spBox = false
            this.$message({
              message: res.message,
              type:'success'
            })
            updateDetail({id:this.spItem.id,contents: '部长', status: 222}).then(res => {
              console.log(res)
              this.getList()
            })
          })
        }
      }
      
    },
    look(item){
      this.$router.push({
				name: 'LookKeyProject',
				params: {
					options: JSON.stringify(item)
				}
			})
    },
    downloadFile(path){
      if(path){
        window.location.href = path
      } else {
        this.$message({
          message: '暂无上传相关文档！',
          type: 'warning'
        })
      }
    },
		// 编辑
    write(item, index) {
			this.$router.push({
				name: 'WriteDetail',
				params: {
					options: JSON.stringify(item)
				}
			})
		},
		// 落实情况
		luoshi(item){
			console.log('落实',item)
			this.$router.push({
				name: 'Implement',
				params: {
					options: JSON.stringify(item)
				}
			})
		},
		// 进度完成情况
		jindu(item){
			console.log('进度',item)
			this.$router.push({
				name: 'Progress',
				params: {
					options: JSON.stringify(item)
				}
			})
		},
		// 确认开始
		sureBegin(item){
			item.status = 1
			updateDetail(item).then(res => {
				console.log(res)
				this.$message({
					message: res.message,
					type: 'success'
				})
			})
		},
		// 删除信息
    deleteRow(item) {
      console.log("删除");
      deleteDetail(item.id).then(res => {
        console.log(res)
        this.$message({
          showClose: true,
          message: res.message,
          type: 'success'
        });
        this.getList()
      })
    },
    goPrev(page) {
      console.log(page);
      this.pages = pages--
      this.getList()
    },
    goNext(page) {
      console.log(page);
      this.pages = pages++
      this.getList()
    },
    goPage(page){
      this.pages = page
      this.getList()
    },
    resetList() {
      this.bumen = ""
    },
    addPeople() {
      this.$router.push({
				name: 'WriteDetail'
			})
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
  color: #18a05e;
  background-color: transparent;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}

.app-container {
  padding: 10px;
}
.downloadfile{
  color: #18a05e;
  cursor: pointer;
}
.zese{
  color: #7a13db
}
.status {
  border-radius: 3px;
  font-size: 14px;
  width: 50px;
  color: #fff;
  background: #777777;
  margin: 0 auto;
}
.status-active {
  background: #18a05e;
}
.morehandle {
  display: flex;
  flex-direction: column;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.zd3-title {
	height: 80px;
	display: flex;
	align-items: center;
	padding: 0 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
		color: #333;
		margin-right: 30px;

		> span {
			padding-right: 20px;
		}

		> input {
			width: 200px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}

	> h3 {
		width: 64px;
		height: 32px;
		background: #18a05e;
		border-radius: 3px;
		margin: 0 30px 0 0;
		color: #fff;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
	}

	> h4 {
		width: 64px;
		height: 32px;
		border-radius: 3px;
		border: 1px solid rgba(0, 0, 0, 0.1);
		color: #333;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
		margin-right: 30px;
	}
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e !important;
  color: #fff;
}
.zd3-btm /deep/.btn-prev:after {
  content: "上一页";
}
.zd3-btm /deep/.btn-next:before {
  content: "下一页";
}
.zd3-btm /deep/.btn-prev,
.zd3-btm /deep/.btn-next {
  width: 65px !important;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
}
.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.3);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
.orderStatus {
  display: flex;
	justify-content: center;
  > p {
    padding: 0px 5px;
    color: #fff;
    border-radius: 2px;
    margin: 0 0px 0 0;
  }
  .blue {
    background: #3a87ad;
  }
  .green {
    background: #18a05e;
  }
  .yellow {
    background: #ff7a0e;
  }
  .red {
    background: #c60000;
  }
  .zise{
    background: #c7ab10
  }
}
</style>
